package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.AppAllows;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.apache.commons.lang3.StringUtils;

//2015.11.4

/**
 * Created by shenyue on 2015/11/4.
 */
public class AppAllowsConvert {
    public static DBObject castAppAllowsToDBObject(AppAllows appAllows) {
        DBObject dbo = new BasicDBObject();
        if (appAllows.getId() != null) {
            dbo.put("_id", appAllows.getId());
        }
        if (appAllows.getAppVer() != null)
            dbo.put("appVer", appAllows.getAppVer());

        if (StringUtils.isNotBlank(appAllows.getCpIds())) {
            dbo.put("cpIds", appAllows.getCpIds());
        } else {
            dbo.put("cpIds", "");
        }

        return dbo;


//        DBObject dbo = new BasicDBObject();
//        if (device.getId() != null) {
//            dbo.put("_id", device.getId());
//        }
//        dbo.put("platformId",device.getPlatformId());
//        dbo.put("sysVer", device.getSysVer());
//        dbo.put("model", device.getModel());
//        dbo.put("appVer", device.getAppVer());
//        dbo.put("corporationId", device.getCorporationId());
//        dbo.put("channelId", device.getChannelId());
//        return dbo;
    }

    public static AppAllows castDBObjectToAppAllows(DBObject dbObject) {
        AppAllows appAllows = new AppAllows();
        if (dbObject != null) {
            appAllows.setId(ObjUtils.toLong(dbObject.get("_id")));
            appAllows.setAppVer(ObjUtils.toInteger(dbObject.get("appVer")));
            appAllows.setCpIds(ObjUtils.toString(dbObject.get("cpIds")));
        }

        return appAllows;
    }
}
